package com.uroad.jilinpda.modle;

import android.text.TextUtils;

import com.android.util.MyUtil;
import com.uroad.jilinpda.bleactivation.Util;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author 40377
 * @version V1.0
 * @Date 2020/1/10 15:45
 * @Description: ${TODO}(CPC卡出入口信息)
 */
public class CpcEntryExitInfoMDL implements Serializable {
    private boolean bOK;
    private int vehicleType;//车型
    private String hexPlateNumber;//车牌号码
    private int plateColor;//车牌颜色
    private String hexRoadNetworkNumber;//入口收费路网号
    private String hexTollGate;//入口收费站号
    private String tollGate10;//入口收费站号10进制
    private int laneNumber = 2;//入口收费车道号
    private int dsrcStatus;//5.8G模块工作状态
    private int entryTime;//入口时间
    private int entryExitStatus;//出入口状态
    private int vehicleClass;//车种
    private String wokerId;//入口收费员号
    private int entryShift = 1;//入口班次
    private int vehAxle=2;//轴数
    private int vehTotalMass;//货车总重
    private int vehLimitWeight;//核定载重
    private byte specialVehInfo;//特殊货车信息
    private int effflag;//标志 1 无卡    2 纸券    3 cpc卡  4 etc单卡
    private String reserve;
    private String hexEF01Info;
    private String mediaNo; //纸券编号
    private String enStationId;//入口站id
    private String enStationHex;//入口站HEX字符串
    private String hex;//入口站hex
    private String enTollLaneId;//入口车道id
    private String enTollHex;//入口车道hex
    private int mediaType;//入口通行介质  1位数字：1-OBU2-CPC卡3-纸券9-无通行介质(无卡时入口查询接口返回的通行介质)
    private String cpuNetNo;//cpu卡网络号
    private String servID;//公务号
    private String etcCardNo;//etc卡号
    private String etc0015;//etc单卡0015文件
    private String etc0019;//etc单卡0019文件
    private String vehicleSign = "FF";//车辆识别标识

    public String getVehicleSign() {
        return vehicleSign == null ? "" : vehicleSign;
    }

    public void setVehicleSign(String vehicleSign) {
        this.vehicleSign = vehicleSign;
    }

    public String getEtc0019() {
        return etc0019 == null ? "" : etc0019;
    }

    public void setEtc0019(String etc0019) {
        this.etc0019 = etc0019;
    }

    public String getEtc0015() {
        return etc0015;
    }

    public void setEtc0015(String etc0015) {
        this.etc0015 = etc0015;
        etcCardNo = etc0015.substring(24, 40);
        cpuNetNo = etc0015.substring(20, 24);
        byte[] tempBytes = Util.HexStringToByteArray(etc0015.substring(82, 86));
        if ("0F".equals(etc0015.substring(80, 82))){
            servID = String.format("%05d", tempBytes[0]*256+tempBytes[1]);
        }else if ("1F".equals(etc0015.substring(80, 82))){
            servID = String.format("%05d", 1*256*256+tempBytes[0]*256+tempBytes[1]);
        }
    }

    public void setEntryExitStatus(int entryExitStatus) {
        this.entryExitStatus = entryExitStatus;
    }

    public String getEtcCardNo() {
        return etcCardNo == null ? "" : etcCardNo;
    }

    public void setEtcCardNo(String etcCardNo) {
        this.etcCardNo = etcCardNo;
    }

    public String getServID() {
        return servID == null ? "" : servID;
    }

    public void setServID(String servID) {
        this.servID = servID;
    }

    public String getCpuNetNo() {
        return cpuNetNo;
    }

    public void setCpuNetNo(String cpuNetNo) {
        this.cpuNetNo = cpuNetNo;
    }

    public int getMediaType() {
        return mediaType;
    }

    public void setMediaType(int mediaType) {
        this.mediaType = mediaType;
    }

    public String getHex() {
        return hex;
    }

    public void setHex(String hex) {
        this.hex = hex;
    }

    public String getEnStationId() {
        return enStationId;
    }

    public String getEnStationHex() {
        return enStationHex == null ? "" : enStationHex;
    }

    public void setEnStationHex(String enStationHex) {
        this.enStationHex = enStationHex;
    }

    public String getEnTollLaneId() {
        return enTollLaneId == null ? "" : enTollLaneId;
    }

    public void setEnTollLaneId(String enTollLaneId) {
        this.enTollLaneId = enTollLaneId;
    }

    public String getEnTollHex() {
        return enTollHex == null ? "" : enTollHex;
    }

    public void setEnTollHex(String enTollHex) {
        this.enTollHex = enTollHex;
    }

    public void setEnStationId(String enStationId) {
        this.enStationId = enStationId;
    }

    public String getMediaNo() {
        return mediaNo;
    }

    public void setMediaNo(String mediaNo) {
        this.mediaNo = mediaNo;
    }

    public CpcEntryExitInfoMDL() {
        this.init();
    }

    private void init() {
        this.bOK = false;
        this.hexPlateNumber = "";
        this.hexRoadNetworkNumber = "";
        this.hexTollGate = "";
        this.tollGate10 = "";
        this.hexEF01Info = "";
    }

    public void setStatus(boolean status) {
        this.bOK = status;
    }

    public boolean getStatus() {
        return this.bOK;
    }

    public void setEntryExitInfo(byte[] EF01) {
        if (EF01 != null && EF01.length >= 30) {
            try {
                this.hexEF01Info = MyUtil.bytesToHexString(EF01, EF01.length);
                this.vehicleType = EF01[0] & 255;
                this.hexPlateNumber = MyUtil.byteToString(EF01, 1, 12);//车牌号码
                this.plateColor = EF01[13] & 255;//车牌颜色
                this.hexRoadNetworkNumber = MyUtil.binToHex(EF01, 14, 2);//入口收费路网号
                this.hexTollGate = MyUtil.binToHex(EF01, 16, 2);//入口收费站号
                this.tollGate10 = String.format("%02d", Long.parseLong(hexTollGate.substring(0, 2), 16)) +//入口收费站号 10进制
                        String.format("%02d", Long.parseLong(hexTollGate.substring(2, 4), 16));
                this.laneNumber = EF01[18] & 255;//入口收费车道号
                this.entryTime = 0;

                for (int i = 0; i < 4; ++i) {//入口时间
                    this.entryTime = this.entryTime << 8 | EF01[19 + i] & 255;
                }

                this.dsrcStatus = EF01[23] & 255;//5.8G模块工作状态
                this.entryExitStatus = EF01[24] & 255;//出入口状态
                this.vehicleClass = EF01[25] & 255;//车种
                this.wokerId = MyUtil.binToHex(EF01, 26, 3);//入口收费员工号
                this.entryShift = EF01[29] & 255;//入口班次
                this.vehAxle = EF01[30] & 255;//轴数
                this.vehTotalMass = Integer.parseInt(MyUtil.binToHex(EF01, 31, 4), 16);
                this.vehLimitWeight = Integer.parseInt(MyUtil.binToHex(EF01, 35, 3), 16);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public String getPlateNumber() {
        return this.hexPlateNumber==null?"":this.hexPlateNumber;
    }

    public void setPlateColor(int plateColor) {
        this.plateColor = plateColor;
    }

    public int getPlateColor() {
        return this.plateColor;
    }

    public String getvehicleTypeAsString() {
        String str;
        switch (vehicleType) {
            case 1:
                str = "客车一型";
                break;
            case 2:
                str = "客车二型";
                break;
            case 3:
                str = "客车三型";
                break;
            case 4:
                str = "客车四型";
                break;
            case 11:
                str = "货车一型";
                break;
            case 12:
                str = "货车二型";
                break;
            case 13:
                str = "货车三型";
                break;
            case 14:
                str = "货车四型";
                break;
            case 15:
                str = "货车五型";
                break;
            case 16:
                str = "货车六型";
                break;
            case 21:
                str = "专项作业车一型";
                break;
            case 22:
                str = "专项作业车二型";
                break;
            case 23:
                str = "专项作业车三型";
                break;
            case 24:
                str = "专项作业车四型";
                break;
            case 25:
                str = "专项作业车五型";
                break;
            case 26:
                str = "专项作业车六型";
                break;
            default:
                str = "未定";
        }

        return str;
    }

    public String getPlateColorAsString() {
        String str;
        switch (this.plateColor) {
            case 0:
                str = "蓝色";
                break;
            case 1:
                str = "黄色";
                break;
            case 2:
                str = "黑色";
                break;
            case 3:
                str = "白色";
                break;
            case 4:
                str = "渐变绿色";
                break;
            case 5:
                str = "黄绿双拼色";
                break;
            case 6:
                str = "蓝白渐变";
                break;
            default:
                str = "未定";
        }

        return str;
    }

    public void setVehicleClass(int vehicleClass) {
        this.vehicleClass = vehicleClass;
    }

    public int getVehicleClass() {
        return this.vehicleClass;
    }

    public String getVehicleClassStr() {
        String str;
        switch (this.vehicleClass) {
            case 0:
                str = "普通车";
                break;
            case 6:
                str = "公务车";
                break;
            case 8:
                str = "军警车";
                break;
            case 10:
                str = "紧急车";
                break;
            case 12:
                str = "免费";
                break;
            case 14:
                str = "车队";
                break;
            case 21:
                str = "绿通车";
                break;
            case 22:
                str = "联合收割机";
                break;
            case 23:
                str = "抢险救灾";
                break;
            case 24:
                str = "集装箱车";
                break;
            case 25:
                str = "大件运输";
                break;
            case 26:
                str = "应急保障车";
                break;
            case 27:
                str = "货车列车或半挂汽车列车";
                break;
            default:
                str = "未定";
        }

        return str;
    }

    public int getVehicleType() {
        return this.vehicleType;
    }

    public String getRoadNetworkNumber() {
        return this.hexRoadNetworkNumber==null?"":this.hexRoadNetworkNumber;
    }

    public String getTollGate() {
        if (TextUtils.isEmpty(hexTollGate) && !TextUtils.isEmpty(tollGate10)){
            String stationHex1 = String.format("%02X", Integer.parseInt(tollGate10.substring(0, 2)));
            String stationHex2 = String.format("%02X", Integer.parseInt(tollGate10.substring(2, 4)));
            String a = stationHex1+stationHex2;
            return a;
        }
        return this.hexTollGate==null?"":this.hexTollGate;
    }

    public String getTollGate10() {
        if (TextUtils.isEmpty(tollGate10) && !TextUtils.isEmpty(hexTollGate)){
            String stationHex1 = String.format("%02d",Long.parseLong(hexTollGate.substring(0,2),16));
            String stationHex2 = String.format("%02d",Long.parseLong(hexTollGate.substring(2,4),16));
            String a = stationHex1+stationHex2;
            return a;
        }
        return tollGate10;
    }

    public void setTollGate10(String tollGate10) {
        this.tollGate10 = tollGate10;
    }

    public int getLaneNumber() {
        return this.laneNumber;
    }

    public void setLaneNumber(int laneNumber) {
        this.laneNumber = laneNumber;
    }

    public int getEntryTime() {
        return this.entryTime;
    }

    public String getEntryTimeWithFormat(String format) {
        Date date = new Date((long) this.entryTime * 1000L);
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        String dateStr = sdf.format(date);
        return dateStr;
    }

    public int getDsrcStatus() {
        return this.dsrcStatus;
    }

    public String getDsrcStatusAsString() {
        String str = "关闭";
        if (this.dsrcStatus == 1) {
            str = "打开";
        }

        return str;
    }

    public int getEntryExitStatusIntValue() {
        return this.entryExitStatus;
    }

    public String getEntryExitStatus() {
        String str;
        if (this.entryExitStatus == 1) {
            str = "封闭式MTC入口";
        } else if (this.entryExitStatus == 2||this.entryExitStatus == 4) {
            str = "封闭式MTC出口";
        } else {
            str = "未定义";
        }

        return str;
    }

    public String getHexEF01Info() {
        return this.hexEF01Info==null?"":this.hexEF01Info;
    }

    public String getWokerId() {
        return this.wokerId == null ? "" : this.wokerId;
    }

    public void setWokerId(String wokerId) {
        this.wokerId = wokerId;
    }

    public int getEntryShift() {
        return this.entryShift;
    }

    public void setEntryShift(int entryShift) {
        this.entryShift = entryShift;
    }

    public int getVehAxle() {
        return this.vehAxle;
    }

    public void setVehAxle(int vehAxle) {
        this.vehAxle = vehAxle;
    }

    public int getVehTotalMass() {
        return this.vehTotalMass;
    }

    public void setVehTotalMass(int vehTotalMass) {
        this.vehTotalMass = vehTotalMass;
    }

    public int getVehLimitWeight() {
        return this.vehLimitWeight;
    }

    public void setVehLimitWeight(int vehLimitWeight) {
        this.vehLimitWeight = vehLimitWeight;
    }

    public byte getSpecialVehInfo() {
        return this.specialVehInfo;
    }

    public void setSpecialVehInfo(byte specialVehInfo) {
        this.specialVehInfo = specialVehInfo;
    }

    public String getReserve() {
        return this.reserve == null ? "" : this.reserve;
    }

    public void setReserve(String reserve) {
        this.reserve = reserve;
    }

    public void setHexPlateNumber(String hexPlateNumber) {
        this.hexPlateNumber = hexPlateNumber;
    }

    public void setVehicleType(int vehicleType) {
        this.vehicleType = vehicleType;
    }

    public void setEntryTime(int entryTime) {
        this.entryTime = entryTime;
    }

    public void setHexRoadNetworkNumber(String hexRoadNetworkNumber) {
        this.hexRoadNetworkNumber = hexRoadNetworkNumber;
    }

    public int getEffflag() {
        return effflag;
    }

    public void setEffflag(int effflag) {
        this.effflag = effflag;
    }

    public void setHexTollGate(String hexTollGate){
        this.hexTollGate = hexTollGate;
    }

}
